<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>枚举值清单</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="language.enumerations.object-differences.html">« 和对象的差异</a></li>
      <li style="float: right;"><a href="language.enumerations.serialization.html">序列化 »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="language.enumerations.html">枚举</a></li>
    <li>枚举值清单</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="language.enumerations.listing" class="sect1">
  <h2 class="title">枚举值清单</h2>

  <p class="para">
   无论是纯粹枚举还是回退枚举，都实现了一个叫 <span class="interfacename"><a href="class.unitenum.html" class="interfacename">UnitEnum</a></span> 的内部接口。
   <code class="literal">UnitEnum</code> 包含了一个静态方法：
   <code class="literal">cases()</code>。
   按照声明中的顺序，<code class="literal">cases()</code> 返回了打包的 array，包含全部定义的条目。
  </p>

  <div class="example-contents">
   <div class="phpcode"><code><span style="color: #000000">
<span style="color: #0000BB">&lt;?php<br />Suit</span><span style="color: #007700">::</span><span style="color: #0000BB">cases</span><span style="color: #007700">();<br /></span><span style="color: #FF8000">//&nbsp;产生：&nbsp;[Suit::Hearts,&nbsp;Suit::Diamonds,&nbsp;Suit::Clubs,&nbsp;Suit::Spades]<br /></span><span style="color: #0000BB">?&gt;</span>
</span>
</code></div>
  </div>


  <p class="para">为 Enum 手动定义 <code class="literal">cases()</code> 方法会导致 fatal 错误。</p>
 </div></div></div></body></html>